<template>
  <div class="login">
    <h1>登陆页</h1>

    <input type="text" placeholder="用户名" v-model="username" /> <br />
    <input type="password" placeholder="密码" v-model="password" /> <br />
    <button @click="login">登陆</button>
  </div>
</template>

<script>
export default {
  name: "LoginView",
  data() {
    return {
      username: "",
      password: "",
    };
  },
  methods: {
    login() {
      //  校验用户密码
      //  跳转到面板页（作为一个方法进行跳转）

      if (this.username && this.password) {
        let usertoken = {
          token: 123321,
          exptime: 10000,
          startlogin: +new Date(),
        };
        for (var key in usertoken) {
          localStorage.setItem(key, usertoken[key]);
        }

        const redirect = this.$route.query.redirect;
        //  如果重定向的路径不存在，就前往默认的面板页
        this.$router.push(redirect || "/platform");
      } else {
        alert("用户名或密码错误");
      }
    },
  },
};
</script>

<style lang="scss" scoped>
.login {
  margin-left: 100px;
}
</style>